﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace SharePointOfView.SPReporting.Common
{
    public class XSLTExtensions
    {
        public double DateDiff(string date1, string date2, string diffType)
        {
            Debug.Write(string.Format("date1 : {0}, date2 : {1}, diffType : {2}", date1, date2, diffType), "XSLTExtensions.DateDiff");
            DateTime dt1 = DateTime.Parse(date1);
            DateTime dt2 = DateTime.Parse(date2);

            TimeSpan tsDiff = dt1 - dt2;

            double res = 0;

            switch (diffType)
            {
                case "d" : // Days
                    res = tsDiff.TotalDays;
                    break;
                case "h": // Hours
                    res = tsDiff.TotalHours;
                    break;
                case "m": // Minutes
                    res = tsDiff.TotalMinutes;
                    break;
                case "s": // Seconds
                    res = tsDiff.TotalSeconds;
                    break;
            }

            return res;
        }
    }
}
